package com.khyr.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khyr.Service.CheckItemService;
import com.khyr.entity.*;
import com.khyr.vo.*;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.List;

/**
 * @author 10515
 */
@RestController
@RequestMapping("/inspect/checkItem")
public class ChargeController {
    @Autowired
    private CheckItemService checkItemService;

    @GetMapping("/selectAllCheckItem")
    public R<List<CheckItem>> selectAllCheckItem() {
        List<CheckItem> checkItems=checkItemService.selectAllCheckItem();
        if (checkItems == null){
            return new R<>(500,"查询失败",null);
        }
        return new R<>(200,"查询成功",checkItems);
    }
    @PostMapping("/queryNeedCheckItem")
    public R<List<CareOrderItem>> queryNeedCheckItem(@RequestBody QueryParamsVO queryParamsVO) {
        List<CareOrderItem> careOrderItems = checkItemService.queryNeedCheckItem(queryParamsVO);
        if (careOrderItems == null){
            return new R<>(500,"查询失败",null);
        }
        return new R<>(200,"查询成功",careOrderItems);
    }
    @GetMapping("/queryCheckItemByItemId/{itemId}")
    public R<QueryCheckItemByItemIdBackVo> queryCheckItemByItemId(@PathVariable String itemId) {
        QueryCheckItemByItemIdBackVo queryCheckItemByItemIdBackVo = checkItemService.queryCheckItemByItemId(itemId);
        if (queryCheckItemByItemIdBackVo == null){
            return new R<>(500,"查询失败",null);
        }
        return new R<>(200,"查询成功",queryCheckItemByItemIdBackVo);
    }
    @PostMapping("/startCheck")
    public R<String> startCheck(@RequestBody QueryCheckItemByItemIdBackVo queryCheckItemByItemIdBackVo) {
        checkItemService.startCheck(queryCheckItemByItemIdBackVo);
        return new R<>(200,"启动检查成功",null);
    }
    @PostMapping("/queryAllCheckingResultForPage")
    public  R<Page<HisCheckResult>> queryAllCheckingResultForPage(@RequestBody QueryAllCheckingResultForPageVo queryAllCheckingResultForPageVo) {
        Page<HisCheckResult> hisCheckResultPage = checkItemService.queryAllCheckingResultForPage(queryAllCheckingResultForPageVo);
        if (hisCheckResultPage == null){
            return new R<>(500,"查询失败",null);
        }
        return new R<>(200,"查询成功",hisCheckResultPage);
    }
    @PostMapping("/completeCheckResult")
    public R<String> completeCheckResult(@RequestBody CompleteCheckResultVo completeCheckResultVo) {
        checkItemService.completeCheckResult(completeCheckResultVo);
        return new R<>(200,"完成检查成功",null);
    }
    @PostMapping("/queryAllCheckResultForPage")
    public R<Page<HisCheckResult>> queryAllCheckResultForPage(@RequestBody QueryAllCheckingResultForPageVo queryAllCheckingResultForPageVo ){
        return checkItemService.queryAllCheckResultForPage(queryAllCheckingResultForPageVo);
    }
}